<template>
  <div>
    <el-transfer
      v-model="value"
      :data="data"
      :titles="['可选车场', '已选车场']"
      :filterable="true"
      :filter-placeholder="请输入车场名称"
      :props="{ key: 'chid', label: 'chname' }"
    ></el-transfer>
    <el-button type="primary" @click="submitChange">返回</el-button>
  </div>
</template>
<script>
import {listHome} from "@/api/pxy-cars/home";

export default {
  data() {
    return {
      value: [], // 已选车场的parkmid数组
      data: [] // 所有车场的数据，格式为[{ parkmid: 'xxx', parkName: 'xxx' }, ...]
    };
  },
  created() {
   this.getHome();
  },
  methods: {
    getHome(){
      listHome().then(response=>{
        this.data = response.rows.map(item => ({
          chid: item.chid,
          chname: item.chname
        }));
        // 获取已选车场的parkmid
        this.value = this.$route.query.chid;
      })
    },
    submitChange() {
        this.$router.push({
          path:'car'
        })
      },
  }
};
</script>
